home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / objectex / ex36.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  1.0 KB  |  48 lines

  1. Program ex36;
  2.  
  3. { Program to demonstrate the TSortedCollection.Insert method }
  4.  
  5. Uses Objects,MyObject,MySortC; 
  6.  { For TMyObject,TMySortedCollection definition and registration }
  7.  
  8. Var C : PSortedCollection;
  9.     M : PMyObject;
  10.     I : Longint;
  11.  
  12. Procedure PrintField (Dummy: Pointer;P : PMyObject);
  13.  
  14. begin
  15.   Writeln ('Field : ',P^.GetField);
  16. end;
  17.  
  18.  
  19. begin
  20.   Randomize;
  21.   C:=New(PMySortedCollection,Init(120,10));
  22.   C^.Duplicates:=True;
  23.   Writeln ('Inserting 100 records at random places.');
  24.   For I:=1 to 100 do
  25.     begin
  26.     M:=New(PMyObject,Init);
  27.     M^.SetField(Random(100));
  28.     C^.Insert(M)
  29.     end;
  30.   M:=New(PMyObject,Init);  
  31.   Repeat;
  32.     Write ('Value to search for (-1 stops) :');
  33.     read (I);
  34.     If I<>-1 then 
  35.       begin
  36.       M^.SetField(i);
  37.       If Not C^.Search (M,I) then
  38.         Writeln ('No such value found')
  39.       else
  40.         begin
  41.         Write ('Value ',PMyObject(C^.At(I))^.GetField);
  42.         Writeln (' present at position ',I);   
  43.         end;
  44.       end;
  45.   Until I=-1;    
  46.   Dispose(M,Done);
  47.   Dispose(C,Done);
  48. end.